package com.space.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.space.entity.User;
import com.space.entity.User1;
import com.space.mapper.UserMapper;
import com.space.service.TUserService;
import com.space.service.UserService;
import com.space.utils.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;


@Api(tags = "测试接口描述",value = "口描述")
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    UserService userService;
    @Autowired
    TUserService tUserService;
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    UserMapper userMapper;
    /**
     *
     * @param name
     * @return
     */
    @GetMapping("/he")
    @ApiOperation(value = "测试接口mysql")
    @ApiImplicitParams({@ApiImplicitParam(name = "name",value = "姓名",required = true)})
    public String test(@RequestParam("name") String name){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",1);
        Page<User> userPage = PageHelper.startPage(0,10);
        List list = userMapper.selectList(queryWrapper);
        User user = userService.getNameById(1);
        System.out.println(user.toString());
        String n = userService.getName(1);
        System.out.println(n);
        System.out.println(userPage.getResult().toString());
        return "  hello " + name;
    }
    @GetMapping("/mo")
    @ApiOperation(value = "测试接口MongoDB")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "整数",required = true)})
    public String testMongodb(@RequestParam("id")int id){
        User1 us = new User1();
        us.setId(id+"");
        us.setName("huahua");
        us.setAge(id+6);
        System.out.println(us.toString());
        User1 usr = tUserService.insertUser(us);
        System.out.println("------------------");
        System.out.println(usr.toString());
        System.out.println("********************");
        long n = tUserService.getCount();
        System.out.println(n);
        System.out.println("+++++++++++++");
        return "success";
    }
    @Autowired
    RedisUtils redisUtils;
    @GetMapping("/re")
    @ApiOperation("redis测试接口")
    @ApiImplicitParams({@ApiImplicitParam(name="key",value = "redis key",required = true),
            @ApiImplicitParam(name="val",value = "redis val",required = true)})
    public String testRedis(@RequestParam("key")String key,@RequestParam("val")String val){
        boolean b = redisUtils.set(key,val,10);
        System.out.println(b);
        String s = (String) redisUtils.get(key);
        System.out.println(s);
        return "success";
    }
}
